class SmugmugException(Exception):
    code = None
    
    def __init__(self, code, message):
        self.code = code
        super(SmugmugException, self).__init__(message)
        
class UnknownError(SmugmugException):
    pass

class InvalidLogin(SmugmugException):
    code = 1

class InvalidSession(SmugmugException):
    code = 3

class InvalidUser(SmugmugException):
    code = 4

class SystemError(SmugmugException):
    code = 5

class WrongFormat(SmugmugException):
    code = 6

class AuthenticationRequired(SmugmugException):
    code = 7
        
class InvalidCategory(SmugmugException):
    code = 8

class InvalidAlbum(SmugmugException):
    code = 9

class InvalidTitle(SmugmugException):
    code = 10
        
class AncientVersion(SmugmugException):
    code = 11

class InvalidSortMethod(SmugmugException):
    code = 12

class InvalidSortDirection(SmugmugException):
    code = 13
        
class InvalidSubCategory(SmugmugException):
    code = 15
    
class InvalidData(SmugmugException):
    code = 16
    
class InvalidApiKey(SmugmugException):
    code = 18
    
# Build a dictionary of SmugmugException defined in this module
exceptions = dict([(cls.code, cls) for cls in locals().values() if type(cls) is type and issubclass(cls, SmugmugException)])

def get(code, message):
    """\
    Get an exception instance associtated with an error code.
    """
    if exceptions.has_key(code):
        return exceptions[code](code, message)

    return UnknownError(code, message)